package com.umeox.watch.moto.dataservice.mqtt.request;

import com.alibaba.fastjson.JSONObject;
import com.umeox.moto.common.log.Logger;
import com.umeox.moto.mqtt.request.MqttPublishRequest;
import com.umeox.watch.moto.dataservice.utils.GuavaCacheUtil;

/**
 * 客户端发布的RPC请求
 */
public class ClientChatRpcRequest extends MqttPublishRequest {

    public ClientChatRpcRequest(String topicPrefix, String requestId, Object params) {
        if (!(params instanceof JSONObject)) {
            Logger.e("params is not type of JSONObject");
            return;
        }
        JSONObject requestBody = (JSONObject) params;
        this.requestId = requestId;
        this.topic = topicPrefix + requestId;
        this.qos = 0;
        this.payloadObj = requestBody.toString();
        this.replyTopic = topic.substring(0, topicPrefix.lastIndexOf("/")) + "_reply/" + requestId;


        GuavaCacheUtil.put(requestId, requestBody.getString("method"));
    }
}
